Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature parameters #22

Closed

Conversation

sebastianhoitz
Copy link
Contributor

This allows the user to pass arguments to the translate method that can get placed into the string, like this:

{{_ "Hello %s, it is %s" name weekDay}}

The parser will match the string and ignore the options.

@smhg
Copy link
Collaborator

smhg commented Feb 27, 2014

Thank you for the effort! You are however not the first one to suggest this.

The thing is, handlebars-xgettext should work pretty much exactly like xgettext (used for other languages, like JavaScript).
(Maybe one day, xgettext can even parse Handlebars and handlebars-xgettext becomes obsolete.)
This means string replacement is not something handlebars-xgettext should know about.

Some background
Handlebars' philosophy is: templates should be simple. Because of this, there is no way to wrap helpers (handlebars 1.3.0 now supports subexpressions). This leads many people to a solution like yours, where you do multiple things in one fat helper (string replacement and translation).

The better way however, is to pass the end-result to your template:

handlebarsTemplate({
  hello: stringReplacement(gettext('Hello %s, it is %s'), name, weekDay)
});

Your template can then simply contain this:

<h1>{{hello}}</h1>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants